package com.jinniulive.platform.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jinniulive.platform.R;

import java.util.List;

/**
 * Created by Administrator on 2016/12/2.
 */

public class SubPopupAdapter extends RecyclerView.Adapter<SubPopupAdapter.SubPopupViewHolder> {

    private Context mContext;
    private List<Drawable> mData;
    private View.OnClickListener mOnClickListener;

    public SubPopupAdapter(Context context, List<Drawable> data) {
        mContext = context;
        mData = data;
    }

    @Override
    public SubPopupViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sub_popup, parent, false);
        SubPopupViewHolder viewHolder=new SubPopupViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(SubPopupViewHolder holder, int position) {
                holder.mImageView.setImageDrawable(mData.get(position));
        if (mOnClickListener!=null){
            holder.mImageView.setOnClickListener(mOnClickListener);
        }

    }
    public void setClickListener(View.OnClickListener onClickListener){
        mOnClickListener = onClickListener;
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public static class SubPopupViewHolder extends RecyclerView.ViewHolder {
        private ImageView mImageView;
        public SubPopupViewHolder(View itemView) {
            super(itemView);
            mImageView = (ImageView) itemView.findViewById(R.id.item_sub_popup_iv);
        }
    }

}
